<?php


namespace app\api\controller;


use app\api\model\UserWalletLogModel;
use app\api\model\UserWalletModel;
use app\api\validate\UserWalletValidate;
use app\common\controller\Api;

class UserWallet extends Api
{

    protected $noNeedLogin = [];
    protected $noNeedRight = [];

    /**
     * 钱包详情
     */
    public function index(UserWalletModel $model)
    {
        $user_id = $this->uid;
        $info = $model->where('user_id',$user_id)->find();
        $data = [
            'info' => $info,
        ];
        $this->ajaxSuccess($data);
    }

    /**
     * 资金记录
     */
    public function logList(UserWalletLogModel $model, UserWalletValidate $validate)
    {
        $param = $this->request->param();
        //数据验证
        $validate_result = $validate->scene('log_list')->check($param);
        if (!$validate_result) {
            $this->error($validate->getError());
        }
        $user_id = $this->uid;
        $num = 10;
        $page = $param['page'];

        $where = [
            'user_id' => $user_id
        ];

        $list = $model
            ->where($where)
            ->page($page)
            ->limit($num)
            ->select();
        $count = $model->where($where)->count();
        $allpage = (string)ceil($count/$num);

        $data = [
            'list' => $list,
            'page' => $page,
            'allpage' => $allpage,
        ];
        $this->ajaxSuccess($data);
    }
}
